package com.ple.app.importdata;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.preference.PreferenceManager;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TabHost;

import com.ple.app.jzsf.R;

public class Input_Activity extends TabActivity {

    private TabHost tabHost;
    private GestureDetector gestureDetector;
    private int index=0;//tabhost选项
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_input_);



        tabHost=this.getTabHost();
        tabHost.setup();
        Intent seed_intent=new Intent(this,InputSeed_Activity.class);
        Intent manure_intent=new Intent(this,Inputmanure_Activity.class);
        Intent culitivate_intent=new Intent(this,Inputcultivate_Activity.class);
        Intent soil_intent=new Intent(this,Inputsoildata_Activity.class);
        TabHost.TabSpec tab1=tabHost.newTabSpec("tab1").setIndicator("种子信息").setContent(seed_intent);
        TabHost.TabSpec tab2=tabHost.newTabSpec("tab2").setIndicator("肥料信息").setContent(manure_intent);
        TabHost.TabSpec tab3=tabHost.newTabSpec("tab3").setIndicator("栽培管理").setContent(culitivate_intent);
        TabHost.TabSpec tab4=tabHost.newTabSpec("tab2").setIndicator("土壤气象").setContent(soil_intent);
        tabHost.addTab(tab1);
        tabHost.addTab(tab2);
        tabHost.addTab(tab3);
        tabHost.addTab(tab4);


        gestureDetector=new GestureDetector(this, new GestureDetector.OnGestureListener() {
            @Override
            public boolean onDown(MotionEvent e) {

                return true;
            }

            @Override
            public void onShowPress(MotionEvent e) {

            }

            @Override
            public boolean onSingleTapUp(MotionEvent e) {
                return false;
            }

            @Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                return false;
            }

            @Override
            public void onLongPress(MotionEvent e) {

            }

            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                float x = e2.getX() - e1.getX();
                //float y = e2.getY() - e1.getY();

                if (x < 0) {
                    if(index==3)index=3;

                    else {index+=1;Input_Activity.this.tabHost.setCurrentTab(index);}

                } else if (x > 0) {
                    if(index==0)
                        index =0;
                    else {index-=1; Input_Activity.this.tabHost.setCurrentTab(index);}

                }
                return true;
            }
        });

    }//oncrerat

    /**
     * 屏幕事件监听
     * @param event
     * @return
     */
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return gestureDetector.onTouchEvent(event);
    }
}
